package com.tianji.aigc.Controller;

import com.tianji.aigc.Service.IChatService;
import com.tianji.aigc.domain.VO.ChatEventVO;
import com.tianji.aigc.domain.dto.ChatDTO;
import com.tianji.common.annotations.NoWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Autowired
    private IChatService chatService;

    @NoWrapper
    @PostMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatEventVO> chat(@RequestBody ChatDTO dto) {
        return chatService.chat(dto.getQuestion(), dto.getSessionId());

    }
    @PostMapping("/stop")
    public void stop(@RequestParam("sessionId") String sessionId) {
        chatService.stop(sessionId);
    }
}
